/*
 * @Description:
 * @Autor: HuiSir<273250950@qq.com>
 * @Date: 2024-05-30 09:50:07
 * @LastEditTime: 2024-08-22 00:04:29
 */
import smilies from "../inc/smilies.js"

const commentListHandle = (comments) => {
  if (!comments) return []
  return comments.map((item) => {
    item.comment_content = item.comment_content.replace(
      /:([a-z?!]+):/g,
      (_word, $1) => {
        const smile = smilies.find((item) => item.code === $1)
        if (!smile) return `<img class="smiley-img" src="${window.isDev ? './assets/smilies/icon_smile.png' : window.themeUriPath + '/assets/smilies/icon_smile.png'
          }" />`
        return `<img class="smiley-img" src="${window.isDev ? smile.img : window.themeUriPath + smile.img.slice(1)
          }" />`
      }
    )

    if (item.child_list && item.child_list.length) {
      item.child_list = commentListHandle(item.child_list)
    }

    return item
  })
}

export default commentListHandle
